import re

import arial10


class FitSheetWrapper(object):
    """Try to fit columns to max size of any entry.
    To use, wrap this around a worksheet returned from the
    workbook's add_sheet method, like follows:

     sheet = FitSheetWrapper(book.add_sheet(sheet_name))

    The worksheet interface remains the same: this is a drop-in wrapper
    for auto-sizing columns.
    """

    def __init__(self, sheet):
        self.sheet = sheet
        self.widths = dict()

    def write(self, r, c, label='', *args, **kwargs):
        self.sheet.write(r, c, label, *args, **kwargs)
        width = int(arial10.fitwidth(label))
        if width > self.widths.get(c, 0):
            self.widths[c] = width
            self.sheet.col(c).width = width

    def __getattr__(self, attr):
        return getattr(self.sheet, attr)


# 匹配数字开头(题干匹配)
def match_num_start(des):
    if re.match(r'^\d+?\.', des):
        return True
    return False


# 匹配字母开头(选项匹配)
def match_alpha_start(des):
    if re.match(r'^[A-Z]\.', des):
        return True
    return False


if __name__ == '__main__':
    print("util.py")
    print(match_num_start('100.问题1'))
    print(match_num_start('100问题1'))
    print(match_alpha_start('A.选项A'))
    print(match_alpha_start('B选项B'))
